<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('会议信息列表')"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>会议名称：</label>
                            <input type="text" name="meetingName"/>
                        </li>
                        <!--<li>
                            <label>主持人：</label>
                            <input type="text" name="host"/>
                        </li>-->
                        <li>
                            <label>开始时间：</label>
                            <input type="text" class="datetime-input" placeholder="请选择开始时间" name="startTime"/>
                        </li>
                        <li>
                            <label>结束时间：</label>
                            <input type="text" class="datetime-input" placeholder="请选择结束时间" name="endTime"/>
                        </li>
                        <li>
                            <label>会议地点：</label>
                            <input type="text" name="meetingAddress"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="business:meeting:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <!--            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"-->
            <!--               shiro:hasPermission="business:meeting:edit">-->
            <!--                <i class="fa fa-edit"></i> 修改-->
            <!--            </a>-->
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="business:meeting:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="business:meeting:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('business:meeting:edit')}]];
    var removeFlag = [[${@permission.hasPermi('business:meeting:remove')}]];
    var viewFlag = [[${@permission.hasPermi('business:meeting:view')}]];
    var prefix = ctx + "business/meeting";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "会议信息",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '会议ID',
                    visible: false
                },
                {
                    field: 'meetingName',
                    title: '会议名称'
                },
                {
                    field: 'startTime',
                    title: '开始时间'
                },
                {
                    field: 'endTime',
                    title: '结束时间'
                },
                {
                    field: 'meetingAddress',
                    title: '会议地点'
                },
                {
                    field: 'meetingStatus',
                    title: '会议状态',
                    visible: false
                },
                {
                    field: 'statusStr',
                    title: '会议状态'
                },
                {
                    field: 'meetingPeople',
                    title: '应到人数'
                },
                {
                    field: 'signPeople',
                    title: '实到人数'
                },
                {
                    field: 'leavePeople',
                    title: '请假人数'
                },
                {
                    field: 'absentPeople',
                    title: '缺席人数'
                },
                {
                    field: 'remark',
                    title: '备注',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 20, 'open');
                    }
                },
                {
                    field: 'meetingImg',
                    title: '签到二维码',
                    formatter: function (value, row, index) {
                        return '<a target="_blank" href=' + value + '>二维码</a>';
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.meetingStatus == 0) {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }

                        // 添加下载二维码按钮，适用于所有会议状态
                        // actions.push('<a style="margin-left: 3px;" class="btn btn-info btn-xs" href="javascript:void(0)" onclick="downloadQRCode(\'' + row.meetingImg + '\', \'' + row.meetingName + '\')"><i class="fa fa-download"></i>下载二维码</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + viewFlag + '" href="javascript:void(0)" onclick="showDetail(\'' + row.id + '\')"><i class="fa fa-eye"></i>详情</a>');

                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);

        // 初始化日期时间选择器
        $("input.datetime-input").datetimepicker({
            format: "yyyy-mm-dd HH:ii",
            autoclose: true,
            minView: 0,
            minuteStep: 1
        });
    });

    // 下载二维码函数
    function downloadQRCode(imgUrl, meetingName) {
        // 创建一个隐藏的a标签
        var a = document.createElement('a');
        a.href = imgUrl;
        a.download = meetingName + '签到二维码.png';
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
    }

    // 查看会议签到详情
    function showDetail(id) {
        var url = prefix + "/detail/" + id;
        $.modal.openTab("会议签到列表", url);
    }
</script>
</body>
</html>